<script>
import UFormItem from "../../../../../uni_modules/uview-ui/components/u-form-item/u-form-item.vue";
import uSelect from "../../../../../components/base/u-select/index.vue";
import {getUserInfoApi} from "../../../../../api/common/user";
import {getProjectListApi} from "../../../../../api/common/product";
import {getAgentListApi} from "../../../../../api/common/power-station";
import ModuleCard from "../../../../../components/business/module-card/index.vue";
import {getProjectCompanyList} from "../../../../../api/common/company";
import {getProjectInfoDetailApi} from "../../../../../api/customer";

export default {
  name: "index",
  components: {ModuleCard, uSelect, UFormItem},
  props: {
    value: {
      type: Object,
      default: () => {
        return {}
      }
    },
    formData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    disabled: {
      type: Boolean,
      default: false,
    }
  },
  data(){
    return {
      projectList: [],
      agentList: [], // 代理商列表
      // 租金列表
      rentStandardList: [],
    }
  },
  mounted() {
    this.getProjectList();
    this.getAgentList();
  },
  methods: {
    async getProjectList(){
      const { user } = await getUserInfoApi();
      const { data } = await getProjectListApi({ userId: user.userId, type: 1 });
      this.projectList = data;
    },
    // 获取合作年限和租金下拉列表数据
    async getProjectInfoDetail() {
      const { data } = await getProjectInfoDetailApi(this.$props.formData.projectId);
      this.rentStandardList = data.variables;
    },
    projectChange(project) {
      this.$props.formData.projectCode = project.code;
      this.$props.formData.projectId = project.id;
      this.$props.formData.payCycle = project.payCycle;
      this.getProjectInfoDetail();
      this.$emit('input', { ...this.$props.value })
    },
    // 获取代理商列表
    async getAgentList() {
      const { data } = await getProjectCompanyList();
      this.agentList = data;
    },
  }
}
</script>

<template>
  <module-card title="项目信息">
    <u-form-item label="产品编码" borderBottom>{{formData.projectCode}}</u-form-item>
    <u-form-item label="产品名称" :borderBottom="rentStandardList.length === 0">{{formData.projectName}}</u-form-item>
    <view class="table-wrap" v-if="rentStandardList.length > 0">
      <uni-table border emptyText="没有更多租金相关信息" >
        <!-- 表格数据行 -->
        <uni-tr v-for="(item, index) in rentStandardList" :key="index">
          <uni-td>合作年限</uni-td>
          <uni-td>{{item.startYear}}-{{item.endYear}}年</uni-td>
          <uni-td>租金标准</uni-td>
          <uni-td>{{item.unitPrice}}元/块/年</uni-td>
        </uni-tr>
      </uni-table>
    </view>
    <!--todo...-->
    <u-form-item label="所属项目公司" borderBottom>{{formData.projectName}}</u-form-item>
    <u-form-item label="租金支付方式" borderBottom>{{formData.projectName}}</u-form-item>
    <u-form-item label="备案装机容量" borderBottom>{{formData.beianCapacity}}W</u-form-item>
    <u-form-item label="备案方式" borderBottom>{{formData.beianMode}}</u-form-item>
    <u-form-item label="备案号" borderBottom>{{formData.filingNumber}}</u-form-item>



  </module-card>
</template>

<style scoped lang="scss">
.table-wrap{
  margin-top: 10px;
  margin-bottom: 10px;
}
</style>
